package com.CST.config.service.impl;

import com.CST.config.service.*;
import java.util.*;
import java.util.concurrent.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.*;

/**
 * @Description:redis操作Service的实现类
 * @Author: wzw
 * @Time: 2020/11/17 14:35
 */
@Service
public class RedisServiceImpl implements RedisService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void set(String key, String value) {
	  stringRedisTemplate.opsForValue().set(key, value);
    }

    @Override
    public boolean exists(String key) {
	  return stringRedisTemplate.hasKey(key);
    }

    @Override
    public String get(String key) {
	  return stringRedisTemplate.opsForValue().get(key);
    }

    @Override
    public boolean expire(String key, long expire) {
	  return stringRedisTemplate.expire(key, expire, TimeUnit.SECONDS);
    }

    @Override
    public void remove(String key) {
	  stringRedisTemplate.delete(key);
    }

    @Override
    public Long increment(String key, long delta) {
	  return stringRedisTemplate.opsForValue().increment(key, delta);
    }

    public long delAllKey() {
	  /*执行删除*/
	  final Set<String> keys = stringRedisTemplate.keys("*");
	  return stringRedisTemplate.delete(keys);
    }
}
